version: "3.3"
services:

  spark-master:
    build: ./spark-standalone
    ports:
      - "9090:8080"
      - "7077:7077"
      - "4040-4050:4040-4050"
    volumes:
       - ./spark-standalone/apps:/opt/spark-apps
       - ./spark-standalone/data:/opt/spark-data
       - ./spark-standalone/logs:/opt/spark/logs
       - ./spark-standalone/logs_event:/opt/spark/logs_event

    environment:
      - SPARK_LOCAL_IP=spark-master
      - SPARK_WORKLOAD=master

  spark-worker-a:
    build: ./spark-standalone
    ports:
      - "9091:8080"
      - "7000:7000"
    depends_on:
      - spark-master
    environment:
      - SPARK_MASTER=spark://spark-master:7077
      - SPARK_WORKER_CORES=4
      - SPARK_WORKER_MEMORY=3G
      - SPARK_DRIVER_MEMORY=1G
      - SPARK_EXECUTOR_MEMORY=3G
      - SPARK_WORKLOAD=worker
      - SPARK_LOCAL_IP=spark-worker-a
    volumes:
       - ./spark-standalone/apps:/opt/spark-apps
       - ./spark-standalone/data:/opt/spark-data
       - ./spark-standalone/logs:/opt/spark/logs
       - ./spark-standalone/logs_event:/opt/spark/logs_event

  spark-worker-b:
    build: ./spark-standalone
    ports:
      - "9092:8080"
      - "7001:7000"
    depends_on:
      - spark-master
    environment:
      - SPARK_MASTER=spark://spark-master:7077
      - SPARK_WORKER_CORES=4
      - SPARK_WORKER_MEMORY=3G
      - SPARK_DRIVER_MEMORY=1G
      - SPARK_EXECUTOR_MEMORY=3G
      - SPARK_WORKLOAD=worker
      - SPARK_LOCAL_IP=spark-worker-b
    volumes:
        - ./spark-standalone/apps:/opt/spark-apps
        - ./spark-standalone/data:/opt/spark-data
        - ./spark-standalone/logs_event:/opt/spark/logs_event

  spark-history:
    build: ./spark-standalone
    depends_on:
      - spark-master
    environment:
      - SPARK_WORKLOAD=history-server
      - SPARK_NO_DAEMONIZE=true
    volumes:
      - ./spark-standalone/logs:/opt/spark/logs
      - ./spark-standalone/logs_event:/opt/spark/logs_event
    ports:
      - '18080:18080'

  jupyter:
    build: ./jupyter
    ports:
      - '8888:8888'
      - '4060:4040'
      - '4061:4041'
      - '4062:4042'
      - '4063:4043'
      - '4064:4044'
      - '4065:4045'
    environment:
      - JUPYTER_ENABLE_LAB=yes
    volumes:
      - ./jupyter/workshop/:/home/jovyan
      - ./spark-standalone/logs_event:/opt/spark/logs_event

  minio:
    image: minio/minio:latest
    command: server --console-address ":9001" /data/
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: yandex.practicum
      MINIO_ROOT_PASSWORD: yandex.practicum
    volumes:
      - ./minio/data:/data
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
      interval: 30s
      timeout: 20s
      retries: 3
